﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using ModelGymTauro;

namespace ViewGymTauro
{
    public partial class Deportista_Nuevo : Form
    {
        private Boolean nuevo = false;
        private String pathFile="";
        public Deportista_Nuevo()
        {
           
            InitializeComponent();
        }

        private void buttonSubir_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.ShowDialog();
            pathFile=openFileDialog1.InitialDirectory + openFileDialog1.FileName;
            this.pictureBox1.ImageLocation = pathFile;
            
        }
        

        private void buttonGuardar_Click(object sender, EventArgs e)
        {
            
        }

        private void txtName_Click(object sender, EventArgs e)
        {
            this.lblNoCorrect.Text = "";

        }

        private void txtLastName_Click(object sender, EventArgs e)
        {
            this.lblNoCorrect.Text = "";
        }

        private void txtDni_Click(object sender, EventArgs e)
        {
            this.lblNoCorrect.Text = "";
        }

        private void textBoxInfoTelefono_Click(object sender, EventArgs e)
        {
            this.lblNoCorrect.Text = "";
        }

        private void textBoxInfoCorreo_Click(object sender, EventArgs e)
        {
            this.lblNoCorrect.Text = "";
        }

        private void textBoxInfoDireccion_Click(object sender, EventArgs e)
        {
            this.lblNoCorrect.Text = "";
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            int dni;
            this.lblNoCorrect.Text = "";

            if (txtLastName.Text == "" && this.txtLastName.Text == "" && this.textBoxInfoCorreo.Text == "" && this.textBoxInfoDireccion.Text == ""
                   && this.textBoxInfoTelefono.Text == "")
            {

                this.lblNoCorrect.Text = "Complete todos los campos";

            }

            {
                if (Int32.TryParse(txtDni.Text, out dni))
                {

                    Deportista d = new Deportista();
                    d.Estado = "Registrado";
                    d.Dni = this.txtDni.Text;
                    d.Correo = this.textBoxInfoCorreo.Text;
                    d.Direccion = this.textBoxInfoDireccion.Text;
                    d.Apellido = this.txtLastName.Text;
                    d.Nombre = this.txtName.Text;
                    if (!radioFem.Capture) d.Sexo = 'F';
                    else d.Sexo = 'M';
                    d.UrlFoto = this.pathFile;
                    d.Telefono = this.textBoxInfoTelefono.Text;
                    d.FechaNacimiento = new DateTime(this.dateTimePicker1.Value.Year, this.dateTimePicker1.Value.Month, this.dateTimePicker1.Value.Day);
                    d.FechaRegistro = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day);
                    IniciaSesion.gymMan.addDeportista(d);
                  
                    this.txtDni.Enabled = false;
                    this.textBoxInfoCorreo.Enabled = false;
                    this.textBoxInfoDireccion.Enabled = false;
                    this.txtLastName.Enabled = false;
                    this.txtName.Enabled = false;
                    this.textBoxInfoCorreo.Enabled = false;
                    this.textBoxInfoDireccion.Enabled=false;
                    this.textBoxInfoTelefono.Enabled = false;



                }
                else this.lblNoCorrect.Text = "Los datos que has introducido no son validos";



            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            this.txtDni.Enabled =true ;
            this.textBoxInfoCorreo.Enabled = true;
            this.textBoxInfoDireccion.Enabled = true;
            this.txtLastName.Enabled = true;
            this.txtName.Enabled = true;
            this.textBoxInfoCorreo.Enabled = true;
            this.textBoxInfoDireccion.Enabled = true;
            this.textBoxInfoTelefono.Enabled = true;
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            this.txtDni.Text = "";
            this.textBoxInfoCorreo.Text = "";
            this.textBoxInfoDireccion.Text = "";
            this.txtLastName.Text = "";
            this.textBoxInfoCorreo.Text = "";
            this.textBoxInfoDireccion.Text = "";
            this.textBoxInfoTelefono.Text = "";
            this.txtName.Text = "";
        }

        
    }
}
